﻿
using System.Web.Mvc;
using MvcSampleApplication.Properties;
using System.Linq;

namespace MvcSampleApplication.Controllers
{
    public abstract class BaseController : Controller
    {
        protected string ControllerTitle = string.Empty;

        protected override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            ViewData["SiteTitle"] = string.Format(Settings.Default.jQueryUI_PageTitle, ControllerTitle);

            var description = filterContext.ActionDescriptor
                .GetCustomAttributes(true)
                .FirstOrDefault(x => typeof(System.ComponentModel.DescriptionAttribute).IsAssignableFrom(x.GetType()));

            ViewData["ViewTitle"] = string.Empty;
            if (description != null)
            {
                var t = description as System.ComponentModel.DescriptionAttribute;
                ViewData["ViewTitle"] = t.Description;
            }

            base.OnActionExecuted(filterContext);
        }
    }
}
